home *** CD-ROM | disk | FTP | other *** search
/ NASA Climatology Interdisciplinary Data Collection / NASA Climatology Interdisciplinary Data Collection - Disc 4.iso / software / grads / lib / xyplot.gs < prev   
Encoding:
Text File  |  1998-04-23  |  2.8 KB  |  159 lines

  1. *  Script to draw an XY plot.  
  2. *  Does no Error checking on the input file at all. 
  3. *  Assumes the input file is set up as follows:
  4. *
  5. *    Line 1:  Title
  6. *    Line 2:  X Axis Label
  7. *    Line 3:  Y Axis Label (not drawn; needs a GrADS mod)  
  8. *    Line 4:  Axes Limits:  xmin xmax ymin ymax
  9. *    Line 5:  Axes Labels:  xlow xint ylow yint
  10. *    Rest of lines:  X Y points
  11. *
  12. *  Also assumes that a file has been opened (any file, doesn't
  13. *  matter -- the set command doesn't work until a file has been
  14. *  opened).
  15. *
  16. function main(args)
  17.  
  18. 'clear'
  19.  
  20. if (args='') 
  21.   say 'Enter File Name:'
  22.   pull fname
  23. else
  24.   fname = args
  25. endif
  26.  
  27. *  Read the 1st record: Title
  28.  
  29. ret = read(fname)
  30. rc = sublin(ret,1)
  31. if (rc>0) 
  32.   say 'File Error'
  33.   return
  34. endif
  35. title = sublin(ret,2)
  36.  
  37. *  Read the 2nd record: X Label
  38.  
  39. ret = read(fname)
  40. rc = sublin(ret,1)
  41. if (rc>0) 
  42.   say 'File Error'
  43.   return
  44. endif
  45. xlab = sublin(ret,2)
  46.  
  47. *  Read the 3rd record: Y Label
  48.  
  49. ret = read(fname)
  50. rc = sublin(ret,1)
  51. if (rc>0) 
  52.   say 'File Error'
  53.   return
  54. endif
  55. ylab = sublin(ret,2)
  56.  
  57. *  Read the 4th record: xmin xmax ymin ymax
  58.  
  59. ret = read(fname)
  60. rc = sublin(ret,1)
  61. if (rc>0) 
  62.   say 'File Error'
  63.   return
  64. endif
  65. rec = sublin(ret,2)
  66. xmin = subwrd(rec,1)
  67. xmax = subwrd(rec,2)
  68. ymin = subwrd(rec,3)
  69. ymax = subwrd(rec,4)
  70.  
  71. xdif = xmax - xmin
  72. xdif = 9.0/xdif
  73. ydif = ymax - ymin
  74. ydif = 6.0/ydif
  75.  
  76. *  Read the 5th record: xlow xint ylow yint
  77.  
  78. ret = read(fname)
  79. rc = sublin(ret,1)
  80. if (rc>0) 
  81.   say 'File Error'
  82.   return
  83. endif
  84. rec = sublin(ret,2)
  85. xlow = subwrd(rec,1)
  86. xint = subwrd(rec,2)
  87. ylow = subwrd(rec,3)
  88. yint = subwrd(rec,4)
  89.  
  90. * Loop on the rest of the records: x y
  91.  
  92. first = 0
  93. 'set ccolor 1'
  94. 'set parea 1 10 1.5 7.5'
  95. 'set line 1 1 6'
  96. 'draw line 1 1.5 10 1.5'
  97. 'draw line 10 1.5 10 7.5'
  98. 'draw line 10 7.5 1 7.5'
  99. 'draw line 1 7.5 1 1.5'
  100. 'set line 1 1 3'
  101.  
  102. while (1)
  103.   ret = read(fname)
  104.   rc = sublin(ret,1)
  105.   if (rc>0) 
  106.     if (rc!=2) 
  107.       say 'File I/O Error'
  108.       return
  109.     endif
  110.     break
  111.   endif
  112.   rec = sublin(ret,2)
  113.   x = subwrd(rec,1)
  114.   y = subwrd(rec,2)
  115.   x = 1.0+(x-xmin)*xdif
  116.   y = 1.5+(y-ymin)*ydif
  117.   say x' 'y
  118.   if (first) 
  119.     'draw line 'xold' 'yold' 'x' 'y
  120.     'set line 0'  
  121.     'draw mark 3 'xold' 'yold' 0.1'
  122.     'set line 1'
  123.     'draw mark 2 'xold' 'yold' 0.1'
  124.   endif
  125.   first = 1
  126.   xold = x
  127.   yold = y
  128. endwhile
  129. 'set line 0'  
  130. 'draw mark 3 'xold' 'yold' 0.1'
  131. 'set line 1'
  132. 'draw mark 2 'xold' 'yold' 0.1'
  133.  
  134. 'set line 1 1 5'
  135. 'set string 1 tc 5'
  136. 'set strsiz 0.15 0.17'
  137. say xlow' 'xint' 'ylow' 'yint
  138. xx = xlow*'1.0'
  139. while (xx<=xmax & xx>=xmin)
  140.   x = 1.0+(xx-xmin)*xdif
  141.   'draw line 'x' 1.5 'x' 1.47'
  142.   'draw string 'x' 1.40 'xx
  143.   xx = xx + xint
  144. endwhile
  145. yy = ylow*'1.0'
  146. 'set string 1 r 5'
  147. while (yy<=ymax & yy>=ymin)
  148.   y = 1.5+(yy-ymin)*ydif
  149.   'draw line 0.97 'y' 1.0 'y
  150.   'draw string 0.90 'y' 'yy
  151.   yy = yy + yint
  152. endwhile
  153.  
  154. 'set string 1 c 6'
  155. 'set strsiz 0.23 0.26'
  156. 'draw string 5.5 7.9 'title
  157. 'set strsiz 0.18 0.20'
  158. 'draw string 5.5 0.8 'xlab
  159.